# 比switch更强大
if __name__ == '__main__':
    score = 'B'
    match score:
        case 'A':
            print('score is A.')
        case 'B':
            print('score is B.')
        case 'C':
            print('score is C.')
        case _:  # _表示匹配到其他任何情况，等同于default
            print('score is ???.')

    age = 15
    match age:
        case x if x < 10:  # 声明变量 x=age=15
            print(f'< 10 years old: {x}')
        case 10:
            print('10 years old.')
        case 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18:  # 多个匹配条件
            print('11~18 years old.')
        case 19:
            print('19 years old.')
        case _:
            print('not sure.')
    print(x)

    args = ['gcc', 'hello.c', 'world.c', 'world2.c', 'world3.c']
    # args = ['clean']
    # args = ['gcc']
    match args:
        # 如果仅出现gcc，报错:
        case ['gcc']:
            print('gcc: missing source file(s).')
        # 出现gcc，且至少指定了一个文件:
        case ['gcc', file1, *files]:  # 声明变量 file1=args[1]，声明列表 files=args[2], args[3]...等等
            print('gcc compile: ' + file1 + ', ' + ', '.join(files))
        # 仅出现clean:
        case ['clean']:
            print('clean')
        case _:
            print('invalid command.')
